import {
  postCouponAdminGiveList,
  getCouponList,
  getProductList,
  postCoupon,
  putCoupon,
  deleteCoupon,
  getUserCouponList,
  postUserCoupon,
  putUserCoupon,
  deleteUserCoupon,
  getCouponRecordList,
  postCouponRecord,
  putCouponRecord,
  deleteCouponRecord
} from '@/api/coupon'
import {
  getToken,
  setToken,
  removeToken
} from '@/utils/auth'
import {
  resetRouter
} from '@/router'

const getDefaultState = () => {
}

const state = getDefaultState()

const mutations = {}

const actions = {
  getCouponList({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      getCouponList(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  postCouponAdminGiveList({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      postCouponAdminGiveList(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  postCoupon({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      postCoupon(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  putCoupon({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      putCoupon(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  deleteCoupon({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      deleteCoupon(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  getUserCouponList({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      getUserCouponList(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  postUserCoupon({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      postUserCoupon(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  putUserCoupon({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      putUserCoupon(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  deleteUserCoupon({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      deleteUserCoupon(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  getCouponRecordList({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      getCouponRecordList(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  getProductList({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      getProductList(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  postCouponRecord({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      postCouponRecord(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  putCouponRecord({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      putCouponRecord(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  deleteRecordCoupon({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      deleteCouponRecord(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
